﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;


//Author: ljj
//Date: 20190625
//Function: BuffAdderEditor
[CustomEditor(typeof(BuffAdder))]
public class BuffAdderEditor : Editor
{
    public override void OnInspectorGUI()
    {
        BuffAdder myTarget = (BuffAdder)target;
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("BUFF", GUILayout.Width(50), GUILayout.ExpandWidth(true));
        EditorGUILayout.LabelField("效率", GUILayout.Width(50), GUILayout.ExpandWidth(true));
        EditorGUILayout.LabelField("时间", GUILayout.Width(50), GUILayout.ExpandWidth(true));
        EditorGUILayout.EndHorizontal();
        for (int i = 0; i < myTarget.buffList.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            BuffInfo tmpBuffInfo = new BuffInfo();
            tmpBuffInfo.buffIndex = EditorGUILayout.Popup(myTarget.buffList[i].buffIndex, System.Enum.GetNames(typeof(ConstOfBuff.BuffType)));
            tmpBuffInfo.effect = EditorGUILayout.FloatField(myTarget.buffList[i].effect);
            tmpBuffInfo.duration = EditorGUILayout.FloatField(myTarget.buffList[i].duration);
            myTarget.buffList[i] = tmpBuffInfo;
            if (GUILayout.Button("x"))
            {
                myTarget.buffList.RemoveAt(i);
                EditorUtility.SetDirty(target);
                return;
            }
            EditorGUILayout.EndHorizontal();
        }
        if (GUILayout.Button("+"))
        {
            myTarget.buffList.Add(new BuffInfo());
            EditorUtility.SetDirty(target);
            return;
        }
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            Undo.RecordObject(myTarget, "obj change");
            //Debug.Log("刷新面板");
        }
    }



}
